﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentValidation;
using CashFlow.ShopManage.Common;
using CashFlow.ShopManage.Models.Order;

namespace CashFlow.ShopManage.Validator.Order
{
    public class QueryOrderModelValidator 
        : AbstractValidator<QueryOrderModel>
    {
        public QueryOrderModelValidator()
        {
            CascadeMode = CascadeMode.Stop;
            RuleFor(x => x.Date).Must(x => RegExpTool.IsDate(x))
                .WithMessage("日期格式不正确！");
            RuleFor(x => x.State).Must(x =>
            {
                if (x.HasValue)
                {
                    return MyCommonTool.ValidateOrderState(x.Value);
                }
                else
                {
                    return true;
                }
            }).WithMessage("订单状态格式不正确！");
        }
    }
}